#include<stdio.h>
int n,id=0,s1[100001],s2[100001],a[10001],size[4];
void input(){
    FILE *fp=fopen("EGIPT.INP","r");
    fscanf(fp,"%d",&n);
    for(int i=1;i<=n;i++){
        fscanf(fp,"%d",&a[i]);
        size[a[i]]++;
    }
    fclose(fp);
}
void process(){
    int i,j,found=0,currentSize=(size[1]>0),index=0,temp;
    for(currentSize=1;currentSize<=2;currentSize++){
        for(i=1;i<=size[currentSize];i++){
            index++;
            if(a[index]==currentSize)continue;            
            if(a[index]==2)
                for(j=size[1]+1;j<=n;j++){
                    if(a[j]==currentSize){
                        found=j;
                        break;
                    }
                }
            else 
                for(j=n;j>i;j--)
                    if(a[j]==currentSize){
                        found=j;
                        break;
                   }
            id++;
            s1[id]=index;
            s2[id]=found;
            
            temp=a[index];
            a[index]=a[found];
            a[found]=temp;
        }
    }
}
void processQuickSort(int begin, int end){
    int i=begin,j=end,key=a[(begin+end)/2],temp;
    if(end<=begin)return;
    do{
        while(a[i]<key)i++;
        while(a[j]>key)j--;
        if(i<=j){
            if(i<j && a[i]!=a[j]){
                
                id++;
                s1[id]=i;
                s2[id]=j;
                
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
            i++;
            j--;
        }
    }while(i<=j);
    processQuickSort(i,end);
    processQuickSort(begin,j);
}
void output(){
    FILE *fp=fopen("EGIPT.OUT","w");
    fprintf(fp,"%d",id);
    for(int i=1;i<=id;i++)
        fprintf(fp,"\n%d %d",s1[i],s2[i]);
    fclose(fp);
}
int main(){
    input();
    process();
    //processQuickSort(1,n);
    output();
    return 0;
}
    

    
